<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%--
  Created by IntelliJ IDEA.
  User: Wangliwei
  Date: 2017/6/18
  Time: 22:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body><%if(session.getAttribute("uname")!=null)
{// 用户已登陆%>
  <%!String DBDRIVER			= "com.mysql.jdbc.Driver" ;
    String DBURL			= "jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8" ;
    String DBUSER			= "root" ;
    String DBPASSWORD		= "" ;
    Connection conn			= null ;
    PreparedStatement pstmt	= null ;
  %><%// 声明一个boolean变量
    boolean flag = false ;
    // 接收参数
    String num = request.getParameter("num") ;
    String name = request.getParameter("name") ;
    String sex = request.getParameter("sex") ;
    String score = request.getParameter("score") ;
    String indate = request.getParameter("indate") ;
  %><%// 更新note表中的数据

  String sql="UPDATE students set name='"+name+"',sex='"+sex+"',score='"+score+"',indate='"+indate+"'where num="+num;
//    String sql = " update students set num =?,name =?,sex =?,score =?,indate =? where num = ?   ";
  try {
    Class.forName(DBDRIVER) ;
      conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD) ;
      pstmt = conn.prepareStatement(sql) ;
/*      pstmt.setString(1, num);
      pstmt.setString(2,name);
    pstmt.setString(3,sex);
      pstmt.setString(4,score);
      pstmt.setString(5,indate);*/



      pstmt.executeUpdate() ;
      pstmt.close() ;
      conn.close() ;
      // 修改成功就执行
      flag = true ;
    }catch(Exception e) {}
  %><%response.setHeader("refresh","2;URL=main.jsp") ;
    if(flag) {%>
  信息修改成功，两秒后跳转到功能列表页！！！<br>
  如果没有跳转，请按<a href="main.jsp">这里</a>！！！
  <%}else{%>
  信息修改失败，两秒后跳转到功能列表页！！！<br>
  如果没有跳转，请按<a href="main.jsp">这里</a>！！！
  <%}%>
  <%}else{// 用户未登陆，提示用户登陆，并跳转
    response.setHeader("refresh","2;URL=Login.jsp") ; %>
  您还未登陆，请先登陆！！！<br>
  两秒后自动跳转到登陆窗口！！！<br>
  如果没有跳转，请按<a href="Login.jsp">这里</a>！！！<br>
  <%}%></center>

</body>
</html>
